package com.guiyang.practice.mess1.mapper;

import com.guiyang.practice.mess1.entity.MessageType;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface MessageTypeMapper {

    @Select("SELECT * FROM message_type WHERE status = 1 ORDER BY create_time DESC")
    List<MessageType> findAllEnabled();

    @Select("SELECT * FROM message_type ORDER BY create_time DESC")
    List<MessageType> findAll();

    @Select("SELECT * FROM message_type WHERE id = #{id}")
    MessageType findById(Long id);

    @Select("SELECT * FROM message_type WHERE type_code = #{typeCode}")
    MessageType findByTypeCode(String typeCode);

    @Insert("INSERT INTO message_type(type_name, type_code, description, status) " +
            "VALUES(#{typeName}, #{typeCode}, #{description}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(MessageType messageType);

    @Update("UPDATE message_type SET type_name=#{typeName}, description=#{description}, " +
            "status=#{status}, update_time=NOW() WHERE id=#{id}")
    int update(MessageType messageType);

    @Update("UPDATE message_type SET status=0, update_time=NOW() WHERE id=#{id}")
    int disable(Long id);

    @Update("UPDATE message_type SET status=1, update_time=NOW() WHERE id=#{id}")
    int enable(Long id);
}